import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },

  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },

  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        name: "Dashboard",
        component: () => import("@/views/dashboard/index"),
        meta: { title: "首页", icon: "index" }
      }
    ]
  },
  {
    path: "/example",
    component: Layout,
    name: "Example",
    meta: {title: "视频", icon: "monitor"},
    children: [
      {
        path: "index",
        name: "video",
        component: () => import("@/views/schema2code/index.vue"),
        meta: {title: "实时预览"}
      },
      {
        path: "tree",
        name: "Tree",
        component: () => import("@/views/tree/index"),
        meta: {title: "录像回放"}
      },
      {
        path: "crop",
        name: "Crop",
        component: () => import("@/views/crop"),
        meta: {title: "视频报警记录"}
      }]
  },
  {
    path: "/links",
    component: Layout,
    name: "links",
    meta: {title: "设备监测", icon: "device"},
    children: [
      {
        path: "link1",
        name: "link1",
        component: () => import("@/views/iframe/link1/index.vue"),
        meta: {title: "可视化"}
      },
      {
        path: "link2",
        name: "link2",
        component: () => import("@/views/iframe/link2/index.vue"),
        meta: {title: "工作台"}
      },
      {
        path: "link3",
        name: "link3",
        component: () => import("@/views/iframe/link3/index.vue"),
        meta: {title: "设备状态"}
      },
      {
        path: "link4",
        name: "link4",
        component: () => import("@/views/iframe/link4/index.vue"),
        meta: {title: "历史查询"}
      },
      {
        path: "link5",
        name: "link5",
        component: () => import("@/views/iframe/link5/index.vue"),
        meta: {title: "分析诊断"}
      },
      {
        path: "link6",
        name: "link6",
        component: () => import("@/views/iframe/link6/index.vue"),
        meta: {title: "故障案例库"}
      },
      {
        path: "link7",
        name: "link7",
        component: () => import("@/views/iframe/link7/index.vue"),
        meta: {title: "诊断报告"}
      },
      {
        path: "link8",
        name: "link8",
        component: () => import("@/views/iframe/link8/index.vue"),
        meta: {title: "开停机统计"}
      },
      {
        path: "link9",
        name: "link9",
        component: () => import("@/views/iframe/link9/index.vue"),
        meta: {title: "到寿预警"}
      }
    ]
  },
  {
    path: "/external-link",
    component: Layout,
    children: [
      {
        path: "/curd/list1",
        name: "curd-list",
        component: () => import("@/views/iframe/link10/index.vue"),
        meta: { title: "工艺流程", icon: "gongyi" }
      }
    ]
  },
  {
    path: "/external-find",
    component: Layout,
    children: [
      {
        path: "/curd/list",
        name: "curd-list2",
        component: () => import("@/views/curd/list/index.vue"),
        meta: { title: "视频巡检", icon: "video" }
      }
    ]
  },
  {
    path: "/external-3d",
    component: Layout,
    children: [
      {
        path: "/curd/list",
        name: "curd-list3",
        component: () => import("@/views/curd/list/index.vue"),
        meta: { title: "三维漫游", icon: "3d" }
      }
    ]
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/sys",
    name: "system",
    meta: {title: "系统管理", icon: "system"},
    children: [
      {
        path: "system1",
        name: "system1",
        component: () => import("@/views/iframe/link1/index.vue"),
        meta: {title: "用户管理"}
      },
      {
        path: "system2",
        name: "system2",
        component: () => import("@/views/iframe/link2/index.vue"),
        meta: {title: "角色管理"}
      },
      {
        path: "system3",
        name: "system3",
        component: () => import("@/views/iframe/link3/index.vue"),
        meta: {title: "权限管理"}
      },
      {
        path: "system4",
        name: "system4",
        component: () => import("@/views/iframe/link4/index.vue"),
        meta: {title: "日志管理"}
      },
    ]
  },
  // {
  //   path: "external-link",
  //   component: Layout,
  //   children: [
  //     {
  //       path: "https://panjiachen.github.io/vue-element-admin-site/#/",
  //       meta: { title: "External Link", icon: "link" }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
